package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyFiles;
import com.laowang.project.system.service.MyFilesService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 头衔协议Controller
 *
 * @author laowang
 * @date 2023-08-31
 */
@Api(tags = "头衔协议接口")
@RestController
@RequestMapping("/myFiles")
public class MyFilesController extends BaseController {

    @Autowired
    private MyFilesService myFilesService;


    @ApiOperation(value = "小程序端 我的协议列表",notes = "")
    @GetMapping("/web/list")
    public AjaxResult weblist() {
        List<MyFiles> list = myFilesService.selectMyFilesListWeb(null);

        return AjaxResult.success(list);
    }

    @ApiOperation(value = "小程序端 新增我的协议",notes = "")
    @PostMapping("/addXY")
    public AjaxResult addXY(@RequestBody MyFiles myFiles) {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        myFiles.setIsPay(0);
        myFiles.setCreated(new Date());
        myFiles.setUserId(mid);
        myFilesService.insertMyFiles(myFiles);

        return AjaxResult.success(myFiles.getId());
    }


    /**
     * 查询头衔协议列表
     */
    @ApiOperation(value = "查询头衔协议列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyFiles myFiles) {
        startPage();
        List<MyFiles> list = myFilesService.selectMyFilesList(myFiles);
        return getDataTable(list);
    }

    /**
     * 导出头衔协议列表
     */
    @ApiOperation(value = "导出头衔协议列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:export')")
    @Log(title = "头衔协议", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyFiles myFiles) {
        List<MyFiles> list = myFilesService.selectMyFilesList(myFiles);
        ExcelUtil<MyFiles> util = new ExcelUtil<MyFiles>(MyFiles.class);
        return util.exportExcel(list, "myFiles");
    }

    /**
     * 获取头衔协议详细信息
     */
    @ApiOperation(value = "获取头衔协议详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myFilesService.selectMyFilesById(id));
    }

    /**
     * 新增头衔协议
     */
    @ApiOperation(value = "新增头衔协议",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:add')")
    @Log(title = "头衔协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyFiles myFiles) {
        return toAjax(myFilesService.insertMyFiles(myFiles));
    }

    /**
     * 修改头衔协议
     */
    @ApiOperation(value = "修改头衔协议",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:edit')")
    @Log(title = "头衔协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyFiles myFiles) {
        return toAjax(myFilesService.updateMyFiles(myFiles));
    }

    /**
     * 删除头衔协议
     */
    @ApiOperation(value = "删除头衔协议",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myFiles:remove')")
    @Log(title = "头衔协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myFilesService.deleteMyFilesByIds(ids));
    }
}
